﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		SiteConfiguration.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            SiteConfiguration.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 
using System;
using System.Globalization;
using System.Xml.Serialization;

namespace Dexter.Domain.Model {
	/// <summary>
	/// 	This class contains a set of info about the Dexter configuration
	/// </summary>
	[Serializable]
	public partial class SiteConfiguration : DomainEntity {
		[NonSerialized] CultureInfo culture;
		[NonSerialized] TimeZoneInfo timeZone;

		GoogleAnalyticsConfigs googleAnalytics;
		Tracking tracking;
		AdvancedFeatues advancedFeatues;
		CommentConfiguration commentConfiguration;
		SmtpConfiguration smtpConfiguration;
		NotificationConfiguration notificationConfiguration;
		AntispamConfiguration antispamConfiguration;
		UrlBuilderConfiguration urlBuilderConfiguration;
		ElementInListsConfiguration elementInListsConfiguration;
		EnabledPages enabledPages;
		SeoConfiguration seoConfiguration;

		internal SiteConfiguration ( ) {
		}

		public DateTime CreationDate { get; set; }

		public string CultureName { get; set; }

		public string TimeZoneId { get; set; }

		public string PrincipalAuthor { get; set; }

		public string BlogName { get; set; }

		public string FeedBurnerUrl { get; set; }

		public string HeaderCode { get; set; }

		public string FooterCode { get; set; }

		public string ThemeName { get; set; }

		public string SiteLanguage { get; set; }

		[XmlIgnore]
		public TimeZoneInfo TimeZone {
			get { return timeZone ?? ( timeZone = TimeZoneInfo.FindSystemTimeZoneById ( TimeZoneId ) ); }
			set {
				timeZone = value;
				TimeZoneId = value.Id;
			}
		}

		[XmlIgnore]
		public CultureInfo Culture {
			get {
				return culture ??
				       ( culture = !String.IsNullOrEmpty ( CultureName )
				                   	? new CultureInfo ( CultureName )
				                   	: CultureInfo.InvariantCulture );
			}
			set {
				culture = value;
				CultureName = value.Name;
			}
		}

		public Tracking Tracking {
			get { return tracking ?? ( tracking = new Tracking ( ) ); }
			set { tracking = value; }
		}

		public GoogleAnalyticsConfigs GoogleAnalytics { get { return googleAnalytics ?? ( googleAnalytics = new GoogleAnalyticsConfigs ( ) ); } set { googleAnalytics = value; } }

		public AdvancedFeatues AdvancedFeatues { get { return advancedFeatues ?? ( advancedFeatues = new AdvancedFeatues ( ) ); } set { advancedFeatues = value; } }

		public CommentConfiguration CommentConfiguration { get { return commentConfiguration ?? ( commentConfiguration = new CommentConfiguration ( ) ); } set { commentConfiguration = value; } }

		public SmtpConfiguration SmtpConfiguration { get { return smtpConfiguration ?? ( smtpConfiguration = new SmtpConfiguration ( ) ); } set { smtpConfiguration = value; } }

		public NotificationConfiguration NotificationConfiguration { get { return notificationConfiguration ?? ( notificationConfiguration = new NotificationConfiguration ( ) ); } set { notificationConfiguration = value; } }

		public AntispamConfiguration AntispamConfiguration { get { return antispamConfiguration ?? ( antispamConfiguration = new AntispamConfiguration ( ) ); } set { antispamConfiguration = value; } }

		public SeoConfiguration SeoConfiguration { get { return seoConfiguration ?? ( seoConfiguration = new SeoConfiguration ( ) ); } set { seoConfiguration = value; } }

		public UrlBuilderConfiguration UrlBuilder { get { return urlBuilderConfiguration ?? ( urlBuilderConfiguration = new UrlBuilderConfiguration ( ) ); } set { urlBuilderConfiguration = value; } }

		public ElementInListsConfiguration ElementInListsConfiguration { get { return elementInListsConfiguration ?? ( elementInListsConfiguration = new ElementInListsConfiguration ( ) ); } set { elementInListsConfiguration = value; } }

		public EnabledPages EnabledPages { get { return enabledPages ?? ( enabledPages = new EnabledPages ( ) ); } set { enabledPages = value; } }

		/// <summary>
		/// 	Gets the UTC from user time zone.
		/// </summary>
		/// <param name = "dateTime">The date time.</param>
		/// <returns></returns>
		public DateTime GetUtcFromUserTimeZone ( DateTime dateTime ) {
			return TimeZoneInfo.ConvertTimeToUtc ( dateTime, this.TimeZone );
		}

		/// <summary>
		/// 	Gets from UTC to user time zone.
		/// </summary>
		/// <param name = "dateTimeUtc">The date time UTC.</param>
		/// <returns></returns>
		public DateTime GetFromUtcToUserTimeZone ( DateTime dateTimeUtc ) {
			return TimeZoneInfo.ConvertTimeFromUtc ( dateTimeUtc, this.TimeZone );
		}
	}
}
